import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;


	public static void class xfer {
		  public static void main (String [] args ) throws IOException {
			  
		    // create socket
		    ServerSocket servsock = new ServerSocket(13267);
		    while (true) {
		      System.out.println("Waiting...");
		      Socket sock = servsock.accept();
		      System.out.println("Accepted connection : " + sock);

		      // receive file
		      ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
		      FileOutputStream fos = new FileOutputStream ("output.mp3"); //("output"+(files)+".mp3");
		      BufferedOutputStream bos = new BufferedOutputStream(fos);
		      data myDataObject = new data(new byte[1]);
		  	try
		  	{
		  		myDataObject = (data)ois.readObject();
		  	}
		  	catch (ClassNotFoundException e)
		  	{
		  		// TODO Auto-generated catch block
		  		e.printStackTrace();
		  	}

		      byte [] mybytearray  = myDataObject.mybytes;
		      bos.write(mybytearray, 0 ,mybytearray.length);
		      bos.flush();
		      long end = System.currentTimeMillis();
		    //  System.out.println("The transfer took: " + (end-start) + " msec");
		      
		      bos.close();
		      sock.close();
		      }
		    }
	
	
	
	
static int transfer(String filename, String hostaddress, int port)
	{
	
	//Create Socket
    Socket sock = new Socket(hostaddress,port);
    System.out.println("Connecting...");
    // sendfile
    File myFile = new File ("woot.mp3"); // Get file
    byte [] mybytearray  = new byte [(int)myFile.length()]; // Create byte array
    FileInputStream fis = new FileInputStream(myFile); // Create file input stream
    
    BufferedInputStream bis = new BufferedInputStream(fis); // Create buffer input stream from file input stream
    bis.read(mybytearray,0,mybytearray.length);  // read bytes in from stream to array
    
    ObjectOutputStream os = new ObjectOutputStream(sock.getOutputStream());  //create output stream
    System.out.println("Sending...");
    data myDataObject = new data(mybytearray);
    os.writeObject(myDataObject);
    //os.write(mybytearray,0,mybytearray.length);
    os.flush();   //clear buffer
    sock.close();  // close socket
  }
  

	
}